package cn.yshujia.domain;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * @author YShuJia
 * @create 2024/4/23
 * @description 登录用户
 */

@Data
@Component
@NoArgsConstructor
public class LoginUser implements UserDetails {
	
	// TODO
//	private User user;
	
	/*public LoginUser(User user) {
		this.user = user;
	}*/
	
	public Collection<? extends GrantedAuthority> getAuthorities() {
		Set<GrantedAuthority> set = new HashSet<>();
		/*String permissions = this.user.getRole().getPermission();
		String[] permissionsArr = permissions.split(SystemConst.PERMISSION_CONNECT);
		for (String permission : permissionsArr) {
			SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority(permission);
			set.add(simpleGrantedAuthority);
		}*/
		return set;
	}
	
	public Set<String> getPermission() {
		/*String permissions = this.user.getRole().getPermission();
		String[] permissionsArr = permissions.split(SystemConst.PERMISSION_CONNECT);
		return new HashSet<>(Set.of(permissionsArr));*/
		return new HashSet<>();
	}
	
	public String getPassword() {
		return null;
	}
	
	public String getUsername() {
		return null;
	}
	
	public boolean isAccountNonExpired() {
		return true;
	}
	
	public boolean isAccountNonLocked() {
		return true;
	}
	
	public boolean isCredentialsNonExpired() {
		return true;
	}
	
	public boolean isEnabled() {
		return true;
	}
}